{% extends 'layout/main.html' %}
{% from 'macros/_macros.html' import render_pagination %}

{% block content_header %}
<div class="row page-titles">
  <div class="col-md-5 col-8 align-self-center">
    <ol class="breadcrumb">
      <li class="breadcrumb-item"><a href="/">首页</a></li>
      <li class="breadcrumb-item active">专报列表</li>
    </ol>
  </div>
</div>
{% endblock %}


{% block content %}
<div class="row">
  <div class="col-sm">
    {% if model %}
    {% for item in model %}
    <div class="ribbon-wrapper card">
      {% if item.status == 9 %}
      <div class="ribbon ribbon-danger">未审核</div>
      {% else %}
      <div class="ribbon ribbon-success">审核</div>
      {% endif %}
      <div class="card-header">
        <div class="card-title">
          <div class="dt-buttons float-right">
            <a href="{{ url_for('report.download_report', id=item.id) }}" class="btn btn-info" href="#" role="button">下载</a>
            <a href="{{ url_for('site.report_preview', id=item.id) }}" target="_blank" class="btn btn-info" href="#" role="button">预览</a>
            <a href="javascript:void(0)" data-id="{{ item.id }}" class="btn btn-danger" onclick="sa_warning(event)"> 删除 </a>
          </div>
          <h4 class="card-title">{{ item.title }}</h4>
        </div>
        <div class="table-responsive">
          <table class="table">
            <thead>
              <tr>
                <th width="50"> ＃ </th>
                <th> 标题 </th>
                <th width="200"> 单位 </th>
                <th width="100"> 作者 </th>
              </tr>
            </thead>
            <tbody>
              {% for i in item.articles %}
              <tr>
                <td>{{ loop.index }}</td>
                <td>{{ i.title }}</td>
                <td>{{ i.user.company.name }}</td>
                <td>{{ i.user.nickname }}</td>
              </tr>
              {% endfor %}
            </tbody>
          </table>
        </div>
      </div>
    </div>
    {% endfor %}
    {% endif %}
    <div class="row">
      <div class="col-sm justify-content-end">
        {{ render_pagination(pagination) }}
      </div>
    </div>
  </div>
  {% endblock %}

  {% block scripts %}
  {{ super() }}

  <script>
    function sa_warning(e) {
      swal({
        title: "您确定?",
        text: "您确定要删除这个专报吗，删除后原有统计与文章会还原未占有状态!",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的, 我确定!",
        cancelButtonText: "取消操作",
        closeOnConfirm: false
      }, function () {
        window.location.href = '/report/delete/' + e.srcElement.dataset['id']
      })
    }
  </script>
  {% endblock scripts %}